<?php
// +----------------------------------------------------------------------
// | TYCMS [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2015-2016 http://www.rainfer.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: aliang <461321026@qq.com>
// +----------------------------------------------------------------------
namespace app\home\controller;

use think\Cache;
use think\Db;
use think\captcha\Captcha;

class Tuiguang extends Base
{
	public function index()
    {
       $code = input('code','','trim');
       $code = htmlspecialchars(strip_tags($code));
       $member = Db::name("member_list")->where("code",$code)->find();
       
       $setting = config('options');
       $yonghu = [
           'qq'    => $setting['site_qq'],
		   'tel'   => $setting['site_tel'],
		   'qrcode'=> $setting['wx_pic'],
           'code'  => ''
       ];
       
       $uid = session('hid') ? session('hid'):0;
       if(!empty($member)){
          session(null);
          cookie(null);
          //$uid = session('hid') ? session('hid'):0;
          
          //if($uid == 0){
             cookie('procode',$code,7*24*3600);
             session('procode',$code);
          //}
          
         $yonghu = [
		       'qq'    => empty($member['qq']) ? $yonghu['qq']:$member['qq'],
		       'tel'   => empty($member['member_list_tel']) ? $yonghu['tel']:$member['member_list_tel'],
		       'qrcode'=> empty($member['qrcode']) ? $yonghu['qrcode']:$member['qrcode'],
               'code'  => $code 
	     ]; 
		 $yonghu['qrcode'] = '/'.trim($yonghu['qrcode'],'/');
		
       }
       $reffer = input('reffer/s') ? input('reffer/s'):url('home/register/index');
       if(request()->isMobile()){
           //$yuju_arr = config('options.tuiguang_yuju');
           //$yuju_arr = explode("\n",$yuju_arr);
           //$yuju     = $yuju_arr[array_rand($yuju_arr)];
           //$yuju     = str_replace('#url#', '', $yuju);
           
          $yuju       = config('options.fenxiang_yuju');
          $this->assign('site_seo_title',$yuju);  
          if(!empty($yonghu)){
              $this->assign('yonghu',$yonghu);
          } 
           
          return $this->view->fetch();
       }else{
          $this->redirect($reffer);  
       }
	}
}